<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="layui/css/public.css" media="all">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <script type="text/javascript" src="layui/jquery.min.js"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">客户姓名</label>
        <div class="layui-input-block">
            <input type="text" name="custName" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
            <tip>填写自己的姓名。</tip>
        </div>
    </div>
    <!--    <div class="layui-form-item">-->
    <!--        <label class="layui-form-label required">性别</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input type="radio" name="sex" value="男" title="男" checked="">-->
    <!--            <input type="radio" name="sex" value="女" title="女">-->
    <!--        </div>-->
    <!--    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label required">客户手机</label>
        <div class="layui-input-block">
            <input type="number" name="custPhone" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">客户所属行业</label>
        <div class="layui-input-block">
            <input type="text" name="custIndustry" placeholder="请输入行业" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">客户级别</label>
        <div class="layui-input-block">
            <input type="text" name="custLevel" placeholder="请输入级别" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">客户信息来源</label>
        <div class="layui-input-block">
            <input type="number" name="custSource" placeholder="请输入来源" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">客户住址</label>
        <div class="layui-input-block">
            <textarea name="custAddress" class="layui-textarea" placeholder="请输入住址"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script>
    $(function (){
        $.ajax({
            url: '/user/findByUser',
            type: 'post',
            success: function (data) {
                if (data.msg != 1) {
                    alert("您没有登录请重新登录");
                    window.self.location = "index.html";
                    // $.messager.alert({
                    //     title:'提示',
                    //     msg:'读取数据异常：'+map.msg
                    // });
                    return;
                }
            }
        })
    })
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                url: 'dfq/save',
                data: JSON.stringify(data.field),
                contentType: "application/json;charset=utf-8",
                dataType:'json',
                type: "post",
                async: false,//false为同步，这个Ajax请求将整个浏览器锁死
                success:function (d){
                    if (d.msg==1){
                        layer.msg("添加成功", {icon: 6});
                        window.parent.location.reload();//修改成功后刷新父界面
                    }else {
                        layer.msg("添加失败", {icon: 5});
                    }
                }
            })




            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {
            //
            //     // 关闭弹出层
            //     // layer.close(index);
            //
            //
            // });

            return false;
        });

    });
</script>
</body>
</html>